<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create a MIME message based on given envelope and body sections</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.imap-lsub.html">« imap_lsub</a></li>
      <li style="float: right;"><a href="function.imap-mail-copy.html">imap_mail_copy »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.imap.html">IMAP 函数</a></li>
    <li>Create a MIME message based on given envelope and body sections</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.imap-mail-compose" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imap_mail_compose</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imap_mail_compose</span> &mdash; <span class="dc-title">Create a MIME message based on given envelope and body sections</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imap-mail-compose-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imap_mail_compose</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$envelope</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$bodies</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Create a MIME message based on the given <code class="parameter">envelope</code>
   and <code class="parameter">bodies</code> sections.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imap-mail-compose-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">envelope</code></dt>

     <dd>

      <p class="para">
       An associative array of header fields. Valid keys are: <code class="literal">&quot;remail&quot;</code>,
       <code class="literal">&quot;return_path&quot;</code>, <code class="literal">&quot;date&quot;</code>, <code class="literal">&quot;from&quot;</code>, <code class="literal">&quot;reply_to&quot;</code>, <code class="literal">&quot;in_reply_to&quot;</code>, <code class="literal">&quot;subject&quot;</code>,
       <code class="literal">&quot;to&quot;</code>, <code class="literal">&quot;cc&quot;</code>, <code class="literal">&quot;bcc&quot;</code> and <code class="literal">&quot;message_id&quot;</code>, which set the respective message headers to the given <span class="type">string</span>.
       To set additional headers, the key <code class="literal">&quot;custom_headers&quot;</code> is supported, which expects
       an array of those headers, e.g. <code class="code">[&quot;User-Agent: My Mail Client&quot;]</code>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">bodies</code></dt>

     <dd>

      <p class="para">
       An indexed array of bodies. The first body is the main body of the message;
       only if it has a type of <strong><code>TYPEMULTIPART</code></strong>, further bodies
       are processed; these bodies constitute the bodies of the parts.
      </p>
      <p class="para">
       <table class="doctable table">
        <caption><strong>Body Array Structure</strong></caption>
        
         <thead>
          <tr>
           <th>Key</th>
           <th>Type</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><code class="literal">type</code></td>
           <td><span class="type">int</span></td>
           <td>
            The MIME type.
            One of <strong><code>TYPETEXT</code></strong> (default), <strong><code>TYPEMULTIPART</code></strong>,
            <strong><code>TYPEMESSAGE</code></strong>, <strong><code>TYPEAPPLICATION</code></strong>,
            <strong><code>TYPEAUDIO</code></strong>, <strong><code>TYPEIMAGE</code></strong>,
            <strong><code>TYPEMODEL</code></strong> or <strong><code>TYPEOTHER</code></strong>.
           </td>
          </tr>

          <tr>
           <td><code class="literal">encoding</code></td>
           <td><span class="type">int</span></td>
           <td>
            The <code class="literal">Content-Transfer-Encoding</code>.
            One of <strong><code>ENC7BIT</code></strong> (default), <strong><code>ENC8BIT</code></strong>,
            <strong><code>ENCBINARY</code></strong>, <strong><code>ENCBASE64</code></strong>,
            <strong><code>ENCQUOTEDPRINTABLE</code></strong> or <strong><code>ENCOTHER</code></strong>.
           </td>
          </tr>

          <tr>
           <td><code class="literal">charset</code></td>
           <td><span class="type">string</span></td>
           <td>The charset parameter of the MIME type.</td>
          </tr>

          <tr>
           <td><code class="literal">type.parameters</code></td>
           <td><span class="type">array</span></td>
           <td>An associative <span class="type">array</span> of <code class="literal">Content-Type</code> parameter names and their values.</td>
          </tr>

          <tr>
           <td><code class="literal">subtype</code></td>
           <td><span class="type">string</span></td>
           <td>The MIME subtype, e.g. <code class="literal">&#039;jpeg&#039;</code> for <strong><code>TYPEIMAGE</code></strong>.</td>
          </tr>

          <tr>
           <td><code class="literal">id</code></td>
           <td><span class="type">string</span></td>
           <td>The <code class="literal">Content-ID</code>.</td>
          </tr>

          <tr>
           <td><code class="literal">description</code></td>
           <td><span class="type">string</span></td>
           <td>The <code class="literal">Content-Description</code>.</td>
          </tr>

          <tr>
           <td><code class="literal">disposition.type</code></td>
           <td><span class="type">string</span></td>
           <td>The <code class="literal">Content-Disposition</code>, e.g. <code class="literal">&#039;attachment&#039;</code>.</td>
          </tr>

          <tr>
           <td><code class="literal">disposition</code></td>
           <td><span class="type">array</span></td>
           <td>An associative <span class="type">array</span> of <code class="literal">Content-Disposition</code> parameter names and values.</td>
          </tr>

          <tr>
           <td><code class="literal">contents.data</code></td>
           <td><span class="type">string</span></td>
           <td>The payload.</td>
          </tr>

          <tr>
           <td><code class="literal">lines</code></td>
           <td><span class="type">int</span></td>
           <td>The size of the payload in lines.</td>
          </tr>

          <tr>
           <td><code class="literal">bytes</code></td>
           <td><span class="type">int</span></td>
           <td>The size of the payload in bytes.</td>
          </tr>

          <tr>
           <td><code class="literal">md5</code></td>
           <td><span class="type">string</span></td>
           <td>The MD5 checksum of the payload.</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imap-mail-compose-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the MIME message as <span class="type">string</span>,  或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imap-mail-compose-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2995">
    <p><strong>示例 #1 <span class="function"><strong>imap_mail_compose()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$envelope</span><span style="color: #007700">[</span><span style="color: #DD0000">"from"</span><span style="color: #007700">]=&nbsp;</span><span style="color: #DD0000">"joe@example.com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$envelope</span><span style="color: #007700">[</span><span style="color: #DD0000">"to"</span><span style="color: #007700">]&nbsp;&nbsp;=&nbsp;</span><span style="color: #DD0000">"foo@example.com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$envelope</span><span style="color: #007700">[</span><span style="color: #DD0000">"cc"</span><span style="color: #007700">]&nbsp;&nbsp;=&nbsp;</span><span style="color: #DD0000">"bar@example.com"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$part1</span><span style="color: #007700">[</span><span style="color: #DD0000">"type"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">TYPEMULTIPART</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part1</span><span style="color: #007700">[</span><span style="color: #DD0000">"subtype"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"mixed"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$filename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"/tmp/imap.c.gz"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$contents&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$part2</span><span style="color: #007700">[</span><span style="color: #DD0000">"type"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">TYPEAPPLICATION</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part2</span><span style="color: #007700">[</span><span style="color: #DD0000">"encoding"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">ENCBINARY</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part2</span><span style="color: #007700">[</span><span style="color: #DD0000">"subtype"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"octet-stream"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part2</span><span style="color: #007700">[</span><span style="color: #DD0000">"description"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">basename</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$part2</span><span style="color: #007700">[</span><span style="color: #DD0000">"contents.data"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$contents</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$part3</span><span style="color: #007700">[</span><span style="color: #DD0000">"type"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">TYPETEXT</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part3</span><span style="color: #007700">[</span><span style="color: #DD0000">"subtype"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"plain"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part3</span><span style="color: #007700">[</span><span style="color: #DD0000">"description"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"description3"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$part3</span><span style="color: #007700">[</span><span style="color: #DD0000">"contents.data"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"contents.data3\n\n\n\t"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$body</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$part1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$body</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$part2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$body</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$part3</span><span style="color: #007700">;<br /><br />echo&nbsp;</span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #0000BB">imap_mail_compose</span><span style="color: #007700">(</span><span style="color: #0000BB">$envelope</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$body</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

</div></div></div></body></html>